<template>
	<view class="indexs">
		<view class="header header_lan" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo"><image :src="imgUrl + '/dzx_img22.png'" mode="widthFix"></image></view>
					<view class="index_wenben baise">{{ $t('page_hotpinlun.topComments') }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;'">
			<view class="hotpinlun_center">
				<view class="hotpinlun_list">
					<view class="hotpinlun_cont" v-for="(item, index) in arrlist" :key="index">
						<view class="hotpinlun_cont_t">
							<view class="hotpinlun_cont_l">
								<image :src="item.user.avatarUrl" mode="aspectFill"></image>
								<view class="hotpinlun_cont_dis">
									<view class="hotpinlun_cont_t1">{{ item.user.nickName }}</view>
									<view class="hotpinlun_cont_t2">{{ $t('page_hotpinlun.odrder') }}：{{ item.order_sn }}</view>
								</view>
							</view>
							<view class="hotpinlun_cont_r">
								<view class="hotpinlun_cont_t3">{{ item.create_time }}</view>
								<view class="hotpinlun_cont_rxing">
									<block v-for="(items, index1) in star" :key="index1" v-if="index1 < item.score.all"><image :src="imgUrl + '/dzx_img21.png'"></image></block>
								</view>
							</view>
						</view>

						<view class="hotpinlun_cont_b">
							<view class="hotpinlun_cont_b1">{{ item.content }}</view>
							<view class="hotpinlun_cont_blist" @click="previewImage" :data-url="item">
								<view class="hotpinlun_cont_bcont" v-for="(item, index1) in item.image" :key="index1" :data-url="item" :data-index="index1" @click="getIndex">
									<image :src="item.file_path" mode="aspectFill"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="hotpinlun_txt">{{ $t('page_hotpinlun.no_data') }}</view>
			</view>
		</view>
	</view>
</template>

<script>
// pages/shouye/shouye_zkc/shouye_zkc.js
const app = getApp();

let request = require('../../../utils/require');

export default {
	data() {
		return {
			navH: app.globalData.navHeight,
			gaodu: app.globalData.height,
			gaodutops: app.globalData.top,
			imgUrl: app.globalData.imgUrl,

			//分页
			page: 1,
			star: [1, 2, 3, 4, 5],
			ispage: true,
			arrlist: [],
			imgindex: 0,
			//0是热门评论，1是查看评论
			type: 0,
			artimages: [],
			optionsid: ''
		};
	},
	/**
	 * 生命周期函数--监听页面加载
	 */ onLoad(options) {
		var that = this;
		that.type = options.type
		that.optionsid = options.id
		that.remenpinlun();
	},
	onShow() {
		var that = this;
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {},
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {
		if (this.ispage) {
			this.page = this.page + 1
			this.remenpinlun();
		}
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {},
	methods: {
		jumpzuo() {
			uni.navigateBack();
		},
		previewImage(e) {
			var len = e.currentTarget.dataset.url.image.length;
			console.log(e, 888);
			var artimages = this.artimages;
			for (var i = 0; i < len; i++) {
				artimages[i] = e.currentTarget.dataset.url.image[i].file_path;
			}
			uni.previewImage({
				current: this.imgindex,
				urls: this.artimages
			});
		},
		getIndex(e) {
			console.log(e.currentTarget.dataset.index, 8888);
			this.imgindex = e.currentTarget.dataset.index
		},

		//热门评论
		remenpinlun() {
			var that = this;
			var url = '';
			var data = {};

			if (that.type == 0) {
				//热门评论
				url = 'index.php?s=/api/comment/hotMoreComment';
				data = {
					token: uni.getStorageSync('token')
				};
			} else {
				//查看评论
				url = 'index.php?s=/api/comment/OrderComment';
				data = {
					token: uni.getStorageSync('token'),
					order_id: that.optionsid
				};
			}

			request.post(url + `&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					if (that.page > res.data.data.last_page) {
						that.ispage = false
					} else {
						that.arrlist = that.arrlist.concat(res.data.data.data)
						console.log(that.arrlist, '????');
					}
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
			});
		}
	}
};
</script>
<style>
@import './hotpinlun.css';
</style>
